//
//  RootViewController.m
//  UI 豆瓣完整版
//
//  Created by dllo on 15/12/31.
//  Copyright © 2015年 lanou. All rights reserved.
//

#import "RootViewController.h"
#import "MyTableViewCell.h"
#import "MovieModel.h"
#define kWidth self.view.frame.size.width
#define kHeight self.view.frame.size.height
#import "UIImageView+WebCache.h"
#import "BRootViewController.h"
@interface RootViewController ()<UITableViewDataSource, UITableViewDelegate>

@property (nonatomic, retain) UITableView *tableView;
@property (nonatomic, retain) NSMutableArray *arr;
@property (nonatomic, retain) NSMutableArray *Modelarr;

@end

@implementation RootViewController

- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        
    }
    return self;
}

- (void)dealloc {
    [super dealloc];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor cyanColor];
    self.navigationController.navigationBar.translucent = NO;
    self.navigationItem.title = @"活动";
    // Do any additional setup after loading the view.
    
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, kWidth, kHeight) style:UITableViewStylePlain];
    [self.view addSubview:_tableView];
    [_tableView release];
    
    _tableView.delegate = self;
    _tableView.dataSource = self;
    
    [_tableView registerClass:[MyTableViewCell class] forCellReuseIdentifier:@"cell"];
    
    
    NSString *path = [[NSBundle mainBundle] pathForResource:@"activitylist" ofType:@"txt"];
    NSData *data = [NSData dataWithContentsOfFile:path];
    NSMutableDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
    self.arr = dic[@"events"];
    
    self.Modelarr = [NSMutableArray array];
    for (NSDictionary *dic in _arr) {
        MovieModel *model = [MovieModel movieModel];
        [model setValuesForKeysWithDictionary:dic];
        [_Modelarr addObject:model];
    }
    
    
    
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    BRootViewController *brootVC = [[BRootViewController alloc] init];
    UINavigationController *Nav = [[UINavigationController alloc] initWithRootViewController:brootVC];
    
    MovieModel *model = _Modelarr[indexPath.row];
    brootVC.model = model;
    
    
    [self presentViewController:Nav animated:YES completion:^{
        
    }];
    
    
    
    
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 10;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    MyTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    
    
    MovieModel *model = _Modelarr[indexPath.row];
    NSString *str = [model.begin_time substringWithRange:NSMakeRange(5, 11) ];
    NSString *str1 = [model.end_time substringWithRange:NSMakeRange(5, 11)];
    NSString *Str = [NSString stringWithFormat:@"%@-%@", str, str1];
    
    cell.timeLabel.text = Str;
    cell.addressLabel.text = model.address;
    cell.typeLabel.text = [NSString stringWithFormat:@"类型 : %@", model.category_name];
    cell.smallLabel1.text = [NSString stringWithFormat:@"感兴趣 : %@", model.wisher_count];
    cell.smallLabel2.text = [NSString stringWithFormat:@"参加 : %@", model.participant_count];
    cell.blueLabel.text = model.title;

    [cell.bigImg sd_setImageWithURL:[NSURL URLWithString:model.image]];

    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 165;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
